﻿using System;
using System.Collections.Generic;
using System.Text;

namespace NetMicro.HttpClient.Internal
{
    /// <summary>
    /// httpclient polly对象组装
    /// </summary>
    public sealed partial class HttpClientPart
    {
        /// <summary>
        /// 设置最多重试几次：如果为0，则不重试
        /// </summary>
        /// <param name="maxRetryTimes"></param>
        /// <returns></returns>
        public HttpClientPart SetMaxRetryTimes(int maxRetryTimes)
        {
            MaxRetryTimes = maxRetryTimes;
            return this;
        }

        /// <summary>
        /// 设置是否启用polly
        /// </summary>
        /// <param name="isEnablePolly"></param>
        /// <returns></returns>
        public HttpClientPart SetIsEnablePolly(bool isEnablePolly = true)
        {
            IsEnablePolly = isEnablePolly;
            return this;
        }
        /// <summary>
        /// 设置重试间隔（单位：毫秒）：默认100ms
        /// </summary>
        /// <param name="retryIntervalMilliseconds"></param>
        /// <returns></returns>
        public HttpClientPart SetRetryIntervalMilliseconds(int[] retryIntervalMilliseconds)
        {
            RetryIntervalMilliseconds = retryIntervalMilliseconds;
            return this;
        }

        /// <summary>
        /// 设置是否启用熔断
        /// </summary>
        /// <param name="isEnableCircuitBreaker"></param>
        /// <returns></returns>
        public HttpClientPart SetIsEnableCircuitBreaker(bool isEnableCircuitBreaker)
        {
            IsEnableCircuitBreaker = isEnableCircuitBreaker;
            return this;
        }

        /// <summary>
        /// 设置熔断前出现允许错误几次
        /// </summary>
        /// <param name="exceptionsAllowedBeforeBreaking"></param>
        /// <returns></returns>
        public HttpClientPart SetExceptionsAllowedBeforeBreaking(int exceptionsAllowedBeforeBreaking)
        {
            ExceptionsAllowedBeforeBreaking = exceptionsAllowedBeforeBreaking;
            return this;
        }

        /// <summary>
        /// 设置熔断时间（单位：毫秒）：默认1000ms
        /// </summary>
        /// <param name="millisecondsOfBreak"></param>
        /// <returns></returns>
        public HttpClientPart SetMillisecondsOfBreak(int millisecondsOfBreak)
        {
            MillisecondsOfBreak = millisecondsOfBreak;
            return this;
        }



    }
}
